#include "IEBrowserUI.h"
#include <mshtml.h>
#include <atlconv.h>

class CActiveXFrameWnd : public IOleInPlaceFrame
{
public:
    CActiveXFrameWnd(CIEBrowserUI* pOwner) : m_dwRef(1), m_pOwner(pOwner), m_pActiveObject(NULL)
    {
    }
    ~CActiveXFrameWnd()
    {
        if( m_pActiveObject != NULL ) m_pActiveObject->Release();
    }

    ULONG m_dwRef;
    CIEBrowserUI* m_pOwner;
    IOleInPlaceActiveObject* m_pActiveObject;

    // IUnknown
    STDMETHOD_(ULONG,AddRef)()
    {
        return ++m_dwRef;
    }

    STDMETHOD_(ULONG,Release)()
    {
        ULONG lRef = --m_dwRef;
        if (lRef == 0) 
			delete this;
        return lRef;
    }

    STDMETHOD(QueryInterface)(REFIID riid, LPVOID *ppvObject)
    {
        *ppvObject = NULL;
        if (riid == IID_IUnknown) 
			*ppvObject = static_cast<IOleInPlaceFrame*>(this);
        else if (riid == IID_IOleWindow) 
			*ppvObject = static_cast<IOleWindow*>(this);
        else if ( riid == IID_IOleInPlaceFrame)
			*ppvObject = static_cast<IOleInPlaceFrame*>(this);
        else if ( riid == IID_IOleInPlaceUIWindow) 
			*ppvObject = static_cast<IOleInPlaceUIWindow*>(this);
        if (*ppvObject != NULL) 
			AddRef();
        return *ppvObject == NULL ? E_NOINTERFACE : S_OK;
    } 

    // IOleInPlaceFrameWindow
    STDMETHOD(InsertMenus)(HMENU /*hmenuShared*/, LPOLEMENUGROUPWIDTHS /*lpMenuWidths*/)
    {
        return S_OK;
    }

    STDMETHOD(SetMenu)(HMENU /*hmenuShared*/, HOLEMENU /*holemenu*/, HWND /*hwndActiveObject*/)
    {
        return S_OK;
    }

    STDMETHOD(RemoveMenus)(HMENU /*hmenuShared*/)
    {
        return S_OK;
    }

    STDMETHOD(SetStatusText)(LPCOLESTR /*pszStatusText*/)
    {
        return S_OK;
    }

    STDMETHOD(EnableModeless)(BOOL /*fEnable*/)
    {
        return S_OK;
    }
	
	STDMETHOD(TranslateAccelerator)(LPMSG /*lpMsg*/, WORD /*wID*/)
    {
        return S_FALSE;
    }

    // IOleWindow
    STDMETHOD(GetWindow)(HWND* phwnd)
    {
        if (m_pOwner == NULL) 
			return E_UNEXPECTED;
        *phwnd = m_pOwner->GetOwner();
        return S_OK;
    }

    STDMETHOD(ContextSensitiveHelp)(BOOL /*fEnterMode*/)
    {
        return S_OK;
    }

    // IOleInPlaceUIWindow
    STDMETHOD(GetBorder)(LPRECT /*lprectBorder*/)
    {
        return S_OK;
    }

    STDMETHOD(RequestBorderSpace)(LPCBORDERWIDTHS /*pborderwidths*/)
    {
        return INPLACE_E_NOTOOLSPACE;
    }

    STDMETHOD(SetBorderSpace)(LPCBORDERWIDTHS /*pborderwidths*/)
    {
        return S_OK;
    }

    STDMETHOD(SetActiveObject)(IOleInPlaceActiveObject* pActiveObject, LPCOLESTR /*pszObjName*/)
    {
        if (pActiveObject != NULL) 
			pActiveObject->AddRef();
        if (m_pActiveObject != NULL) 
			m_pActiveObject->Release();
        m_pActiveObject = pActiveObject;
        return S_OK;
    }
};

CIEBrowserUI::CIEBrowserUI(HWND hOwner):
              CControlUI(hOwner),
			  m_pUnk(NULL),
			  m_pViewObject(NULL),
			  m_pInPlaceObject(NULL),
			  m_pUnkSite(NULL),
			  m_bCaptured(FALSE),
			  m_bFocused(FALSE),
			  m_bWindowless(FALSE),
			  m_bCreated(FALSE),
			  m_hMemBitmap(NULL),
			  m_pMemBitmap(NULL),
			  m_hMemDc(NULL),
			  m_bInPlaceActive(FALSE),
			  m_dwRef(0)
{
	
}


CIEBrowserUI::~CIEBrowserUI(void)
{
	ReleaseControl();
	if (m_pMemBitmap)
		delete m_pMemBitmap;
	m_pMemBitmap = NULL;
	SAFE_DELTE_OBJECT(m_hMemBitmap);
	SAFE_DELTE_OBJECT(m_hMemDc); 
	
}

void CIEBrowserUI::Draw(Gdiplus::Graphics &g, const Gdiplus::Rect &rcPaint)
{ 
	Gdiplus::Rect rc = m_rcItem;
	if (rc.Intersect(rcPaint))
	{
	    if (m_pViewObject != NULL) 
		{
			Refresh();
			g.DrawImage(m_pMemBitmap, m_rcItem, 0, 0, m_rcItem.Width, m_rcItem.Height, Gdiplus::UnitPixel);
 
		} //end if ( m_pViewObject != NULL) 
	} //end if (rc.Intersect(rcPaint))
}

static void PixelToHiMetric(const SIZEL* lpSizeInPix, LPSIZEL lpSizeInHiMetric)
{
#define HIMETRIC_PER_INCH   2540
#define MAP_PIX_TO_LOGHIM(x,ppli)   MulDiv(HIMETRIC_PER_INCH, (x), (ppli))
#define MAP_LOGHIM_TO_PIX(x,ppli)   MulDiv((ppli), (x), HIMETRIC_PER_INCH)
    int nPixelsPerInchX;    // Pixels per logical inch along width
    int nPixelsPerInchY;    // Pixels per logical inch along height
    HDC hDCScreen = ::GetDC(NULL);
    nPixelsPerInchX = ::GetDeviceCaps(hDCScreen, LOGPIXELSX);
    nPixelsPerInchY = ::GetDeviceCaps(hDCScreen, LOGPIXELSY);
    ::ReleaseDC(NULL, hDCScreen);
    lpSizeInHiMetric->cx = MAP_PIX_TO_LOGHIM(lpSizeInPix->cx, nPixelsPerInchX);
    lpSizeInHiMetric->cy = MAP_PIX_TO_LOGHIM(lpSizeInPix->cy, nPixelsPerInchY);
}

void CIEBrowserUI::SetItem(int x, int y, int w, int h)
{
	CControlUI::SetItem(x, y, w, h);
	if (!m_bCreated)
		CreateControl();
	
	SIZEL hmSize = { 0 };
    SIZEL pxSize = { 0 };
	pxSize.cx = m_rcItem.Width;
	pxSize.cy = m_rcItem.Height;

    PixelToHiMetric(&pxSize, &hmSize);

    if (m_pUnk != NULL)
	{
        m_pUnk->SetExtent(DVASPECT_CONTENT, &hmSize);
    }
    if (m_pInPlaceObject != NULL)
	{
		RECT rc = {x, y, x + w,  y + h}; 
        m_pInPlaceObject->SetObjectRects(&rc, &rc);
    }
	RECT rcPaint = {x, y, x + w, y + h};
	InvalidateMem(rcPaint);
}

BOOL CIEBrowserUI::CreateControl()
{
	ReleaseControl();
    m_bCreated = TRUE;
    IOleControl* pOleControl = NULL;

    HRESULT Hr = -1;
	 
    if (FAILED(Hr)) 
	{
        Hr = ::CoCreateInstance(CLSID_WebBrowser, NULL, CLSCTX_ALL, IID_IOleControl, (LPVOID*)&pOleControl);
    } 

    if (FAILED(Hr)) 
		return false;
    pOleControl->QueryInterface(IID_IOleObject, (LPVOID*) &m_pUnk);
    pOleControl->Release();
    if (m_pUnk == NULL) 
		return false;
 
    // More control creation stuff
    DWORD dwMiscStatus = 0;
    m_pUnk->GetMiscStatus(DVASPECT_CONTENT, &dwMiscStatus);
    IOleClientSite* pOleClientSite = NULL;
    QueryInterface(IID_IOleClientSite, (LPVOID*) &pOleClientSite);
    
    // Initialize control
    if ((dwMiscStatus & OLEMISC_SETCLIENTSITEFIRST) != 0) 
		m_pUnk->SetClientSite(pOleClientSite);
    IPersistStreamInit* pPersistStreamInit = NULL;
    m_pUnk->QueryInterface(IID_IPersistStreamInit, (LPVOID*) &pPersistStreamInit);
    if (pPersistStreamInit != NULL)
	{
        Hr = pPersistStreamInit->InitNew();
        pPersistStreamInit->Release();
    }
    if (FAILED(Hr)) 
		return false;
    if ((dwMiscStatus & OLEMISC_SETCLIENTSITEFIRST) == 0) 
		m_pUnk->SetClientSite(pOleClientSite);
    // Grab the view...
    Hr = m_pUnk->QueryInterface(IID_IViewObjectEx, (LPVOID*) &m_pViewObject);
    if (FAILED(Hr))
		Hr = m_pUnk->QueryInterface(IID_IViewObject2, (LPVOID*) &m_pViewObject);
    if (FAILED(Hr)) 
		Hr = m_pUnk->QueryInterface(IID_IViewObject, (LPVOID*) &m_pViewObject);
    // Activate and done...
    m_pUnk->SetHostNames(OLESTR("UIActiveX"), NULL); 
    if ((dwMiscStatus & OLEMISC_INVISIBLEATRUNTIME) == 0)
	{
		RECT rc = {m_rcItem.X, m_rcItem.Y, m_rcItem.X + m_rcItem.Width, m_rcItem.Y + m_rcItem.Height};
		Hr = m_pUnk->DoVerb(OLEIVERB_INPLACEACTIVATE, NULL, pOleClientSite, 0, GetOwner(), &rc);
        //::RedrawWindow(GetOwner(), &rc, NULL, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE | RDW_INTERNALPAINT | RDW_FRAME);
    }
	if (!m_strHomePage.empty())
	{
		Navigate2(m_strHomePage.c_str());
	}
    return SUCCEEDED(Hr);
}

BOOL CIEBrowserUI::Navigate2(LPCWSTR lpstrUrl)
{
	BOOL bRet = FALSE;
	if (m_pUnk != NULL)
	{			
		IWebBrowser2* pWebBrowser = NULL;
        m_pUnk->QueryInterface(IID_IWebBrowser2, (void**)&pWebBrowser);
        if( pWebBrowser != NULL ) 
		{ 
            bRet = SUCCEEDED(pWebBrowser->Navigate(T2BSTR(lpstrUrl),NULL,NULL,NULL,NULL));  
            pWebBrowser->Release();
        }
	}
	return bRet;
}

void CIEBrowserUI::ReleaseControl()
{ 
    if (m_pUnk != NULL) 
	{
        IObjectWithSite* pSite = NULL;
        m_pUnk->QueryInterface(IID_IObjectWithSite, (LPVOID*) &pSite);
        if (pSite != NULL) 
		{
            pSite->SetSite(NULL);
            pSite->Release();
        }
        m_pUnk->Close(OLECLOSE_NOSAVE);
        m_pUnk->SetClientSite(NULL);
        m_pUnk->Release(); 
        m_pUnk = NULL;
    } 
}

void CIEBrowserUI::SetHomePage(LPCWSTR lpstrUrl)
{
	m_strHomePage.clear();
	if (lpstrUrl)
		m_strHomePage = lpstrUrl;
	if (!m_strHomePage.empty())
	{
		Navigate2(m_strHomePage.c_str());
	}
}
STDMETHODIMP CIEBrowserUI::QueryInterface(REFIID riid, LPVOID *ppvObject)
{
    *ppvObject = NULL;
    if (riid == IID_IUnknown)                      
		*ppvObject = static_cast<IOleWindow *>(this);
    else if (riid == IID_IOleClientSite)  
		*ppvObject = static_cast<IOleClientSite*>(this);
    else if (riid == IID_IOleInPlaceSiteWindowless)
		*ppvObject = static_cast<IOleInPlaceSiteWindowless*>(this);
    else if (riid == IID_IOleInPlaceSiteEx)         
		*ppvObject = static_cast<IOleInPlaceSiteEx*>(this);
    else if (riid == IID_IOleInPlaceSite)           
		*ppvObject = static_cast<IOleInPlaceSite*>(this);
    else if (riid == IID_IOleWindow)                
		*ppvObject = static_cast<IOleWindow*>(this);
    else if (riid == IID_IOleControlSite)          
		*ppvObject = static_cast<IOleControlSite*>(this);
    else if (riid == IID_IOleContainer)             
		*ppvObject = static_cast<IOleContainer*>(this);
    else if (riid == IID_IObjectWithSite)           
		*ppvObject = static_cast<IObjectWithSite*>(this);
    if (*ppvObject != NULL) 
		AddRef();
    return *ppvObject == NULL ? E_NOINTERFACE : S_OK;
}

STDMETHODIMP_(ULONG) CIEBrowserUI::AddRef()
{
    return ++m_dwRef;
}

STDMETHODIMP_(ULONG) CIEBrowserUI::Release()
{
    LONG lRef = --m_dwRef;
    if (lRef == 0) 
		delete this;
    return lRef;
}

STDMETHODIMP CIEBrowserUI::SetSite(IUnknown *pUnkSite)
{
	if (m_pUnkSite != NULL) 
	{
        m_pUnkSite->Release();
        m_pUnkSite = NULL;
    }
    if (pUnkSite != NULL) 
	{
        m_pUnkSite = pUnkSite;
        m_pUnkSite->AddRef();
    }
    return S_OK;
}

STDMETHODIMP CIEBrowserUI::GetSite(REFIID riid, LPVOID* ppvSite)
{
    if (ppvSite == NULL) 
		return E_POINTER;
    *ppvSite = NULL;
    if (m_pUnkSite == NULL) 
		return E_FAIL;
    return m_pUnkSite->QueryInterface(riid, ppvSite);
}

STDMETHODIMP CIEBrowserUI::SaveObject(void)
{
    return E_NOTIMPL;
}

STDMETHODIMP CIEBrowserUI::GetMoniker(DWORD dwAssign, DWORD dwWhichMoniker, IMoniker** ppmk)
{ 
    if (ppmk != NULL) 
		*ppmk = NULL;
    return E_NOTIMPL;
}

STDMETHODIMP CIEBrowserUI::TransformCoords(POINTL* pPtlHimetric, POINTF* pPtfContainer, DWORD dwFlags)       
{
    return S_OK;
}

STDMETHODIMP CIEBrowserUI::TranslateAccelerator(MSG *pMsg, DWORD grfModifiers)
{
    return S_FALSE;
}


void CIEBrowserUI::InvalidateMem(const RECT &rcPaint)
{
	SAFE_DELTE_OBJECT(m_hMemBitmap);
	SAFE_DELTE_OBJECT(m_hMemDc); 
	HDC hdc = ::GetDC(m_hOwner);
    HDC hdcPaint = ::GetDC(GetDesktopWindow());
  
	m_hMemDc = ::CreateCompatibleDC(hdcPaint);
	m_hMemBitmap = ::CreateCompatibleBitmap(hdcPaint, rcPaint.right - rcPaint.left, rcPaint.bottom - rcPaint.top);
	HBITMAP hOldBitmap = (HBITMAP)::SelectObject(m_hMemDc, m_hMemBitmap);

	::SelectObject(m_hMemDc, hOldBitmap);
	::ReleaseDC(GetDesktopWindow(), hdcPaint);
	::ReleaseDC(m_hOwner, hdc);
	Refresh();
}

STDMETHODIMP CIEBrowserUI::GetContainer(IOleContainer** ppContainer)
{
	OutputDebugString(L"GetContainer\n");
    if (ppContainer == NULL) 
		return E_POINTER;
    *ppContainer = NULL;
    HRESULT Hr = E_NOTIMPL;
    if (m_pUnkSite != NULL) 
		Hr = m_pUnkSite->QueryInterface(IID_IOleContainer, (LPVOID*) ppContainer);
    if (FAILED(Hr)) 
		Hr = QueryInterface(IID_IOleContainer, (LPVOID*) ppContainer);
    return Hr;
}

void CIEBrowserUI::Refresh()
{
    if ((m_pViewObject != NULL) && m_hMemDc)
	{
		if (m_pMemBitmap)
			delete m_pMemBitmap;		
		RECTL rc = {0, 0, m_rcItem.Width, m_rcItem.Height};
		HBITMAP hOldBitmap = (HBITMAP)::SelectObject(m_hMemDc, m_hMemBitmap);
	    int iSaveDc = ::SaveDC(m_hMemDc);
		m_pViewObject->Draw(DVASPECT_CONTENT, -1, NULL, NULL, NULL, m_hMemDc, &rc, &rc, NULL, NULL);
		m_pMemBitmap = new Gdiplus::Bitmap(m_hMemBitmap, NULL);
		CLSID clsid;
		CControlUI::GetEncoderClsid(L"image/jpg", &clsid);
		m_pMemBitmap->Save(L"E:\\a.jpg", &clsid);
		::RestoreDC(m_hMemDc, iSaveDc);
		::SelectObject(m_hMemDc, hOldBitmap);
	}
}

STDMETHODIMP CIEBrowserUI::ShowObject(void)
{
    if (m_hOwner == NULL)
		return E_UNEXPECTED;
    Refresh();
	Invalidate(); 
    return S_OK;
}

STDMETHODIMP CIEBrowserUI::OnShowWindow(BOOL fShow)
{
    return E_NOTIMPL;
}

STDMETHODIMP CIEBrowserUI::RequestNewObjectLayout(void)
{
    return E_NOTIMPL;
}

STDMETHODIMP CIEBrowserUI::CanWindowlessActivate(void)
{
    return S_OK;   
}

STDMETHODIMP CIEBrowserUI::GetCapture(void)
{
    if (m_hOwner == NULL) 
		return E_UNEXPECTED;
    return m_bCaptured ? S_OK : S_FALSE;
}

STDMETHODIMP CIEBrowserUI::SetCapture(BOOL fCapture)
{
    if (m_hOwner == NULL) 
		return E_UNEXPECTED;
    m_bCaptured = (fCapture == TRUE);
    if (fCapture) 
		::SetCapture(m_hOwner); 
	else 
		::ReleaseCapture();
    return S_OK;
}

STDMETHODIMP CIEBrowserUI::GetFocus(void)
{
    if (m_hOwner == NULL)
		return E_UNEXPECTED;
    return m_bFocused ? S_OK : S_FALSE;
}

STDMETHODIMP CIEBrowserUI::SetFocus(BOOL fFocus)
{
    if (m_hOwner == NULL)
		return E_UNEXPECTED; 
    m_bFocused = (fFocus == TRUE);
    return S_OK;
}

STDMETHODIMP CIEBrowserUI::GetDC(LPCRECT pRect, DWORD grfFlags, HDC* phDC)
{
    if (phDC == NULL) 
		return E_POINTER;
    if (m_hOwner == NULL) 
		return E_UNEXPECTED;
    *phDC = ::GetDC(m_hOwner);
    if ((grfFlags & OLEDC_PAINTBKGND) != 0) 
	{ 
		RECT rc = {m_rcItem.X, m_rcItem.Y, m_rcItem.X + m_rcItem.Width, m_rcItem.Y + m_rcItem.Height};
        //if (!m_bWindowless ) rcItem.ResetOffset();
        ::FillRect(*phDC, &rc, (HBRUSH) (COLOR_WINDOW + 1));
    }
    return S_OK;
}

STDMETHODIMP CIEBrowserUI::ReleaseDC(HDC hDC)
{ 
    if (m_hOwner == NULL) 
		return E_UNEXPECTED;
    ::ReleaseDC(m_hOwner, hDC);
    return S_OK;
}

STDMETHODIMP CIEBrowserUI::InvalidateRect(LPCRECT pRect, BOOL fErase)
{ 
    if (m_hOwner == NULL) 
		return E_UNEXPECTED; 
    return ::InvalidateRect(m_hOwner, pRect, fErase) ? S_OK : E_FAIL;
}

STDMETHODIMP CIEBrowserUI::InvalidateRgn(HRGN hRGN, BOOL fErase)
{
    if (m_hOwner == NULL)
		return E_UNEXPECTED;
    return ::InvalidateRgn(m_hOwner, hRGN, fErase) ? S_OK : E_FAIL;
}

STDMETHODIMP CIEBrowserUI::ScrollRect(INT dx, INT dy, LPCRECT pRectScroll, LPCRECT pRectClip)
{
    return S_OK;
}

STDMETHODIMP CIEBrowserUI::AdjustRect(LPRECT prc)
{
    return S_OK;
}

STDMETHODIMP CIEBrowserUI::OnDefWindowMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT* plResult)
{
    if (m_hOwner == NULL) 
		return E_UNEXPECTED;
    *plResult = ::DefWindowProc(m_hOwner, msg, wParam, lParam);
    return S_OK;
}

STDMETHODIMP CIEBrowserUI::OnInPlaceActivateEx(BOOL* pfNoRedraw, DWORD dwFlags)        
{ 
    if (m_hOwner == NULL) 
		return E_UNEXPECTED; 
    ::OleLockRunning(m_pUnk, TRUE, FALSE);
	HWND hWndFrame = m_hOwner;
    HRESULT Hr = E_FAIL;
    if ((dwFlags & ACTIVATE_WINDOWLESS) != 0)
	{
        m_bWindowless = true;
        Hr = m_pUnk->QueryInterface(IID_IOleInPlaceObjectWindowless, (LPVOID*) &m_pInPlaceObject); 
    }
    if (FAILED(Hr)) 
	{
        m_bWindowless = false; 
        Hr = m_pUnk->QueryInterface(IID_IOleInPlaceObject, (LPVOID*) &m_pInPlaceObject);
    }
    if (m_pInPlaceObject != NULL) 
	{
		Gdiplus::Rect rcItem = m_rcItem;
		RECT rc = {rcItem.X, rcItem.Y, rcItem.X + rcItem.Width, rcItem.Y + rcItem.Height};
        m_pInPlaceObject->SetObjectRects(&rc,  &rc);
    }
    m_bInPlaceActive = SUCCEEDED(Hr);
    return Hr;
}

STDMETHODIMP CIEBrowserUI::OnInPlaceDeactivateEx(BOOL fNoRedraw)       
{
    m_bInPlaceActive = FALSE;
    if (m_pInPlaceObject != NULL) 
	{
        m_pInPlaceObject->Release();
        m_pInPlaceObject = NULL;
    }
    
    return S_OK;
}

STDMETHODIMP CIEBrowserUI::RequestUIActivate(void)
{
    return S_OK;
}

STDMETHODIMP CIEBrowserUI::CanInPlaceActivate(void)       
{
    return S_OK;
}

STDMETHODIMP CIEBrowserUI::OnInPlaceActivate(void)
{
    BOOL bDummy = FALSE;
    return OnInPlaceActivateEx(&bDummy, ACTIVATE_WINDOWLESS);
}

STDMETHODIMP CIEBrowserUI::OnUIActivate(void)
{  
    return S_OK;
}

STDMETHODIMP CIEBrowserUI::GetWindowContext(IOleInPlaceFrame** ppFrame, IOleInPlaceUIWindow** ppDoc, LPRECT lprcPosRect, LPRECT lprcClipRect, LPOLEINPLACEFRAMEINFO lpFrameInfo)
{
    if (ppDoc == NULL) 
		return E_POINTER;
    if (ppFrame == NULL) 
		return E_POINTER;
    if (lprcPosRect == NULL) 
		return E_POINTER;
    if (lprcClipRect == NULL) 
		return E_POINTER;
	if (lprcPosRect)
	{
		lprcPosRect->left = 0;
		lprcPosRect->top = 0;
		lprcPosRect->right = 0;
		lprcPosRect->bottom = 0;
	}
	if (lprcClipRect)
	{
		lprcClipRect->left = 0;
		lprcClipRect->top = 0;
		lprcClipRect->right = 0;
		lprcClipRect->bottom = 0; 
	}
    *ppFrame = new CActiveXFrameWnd(this);
    *ppDoc = NULL;
    ACCEL ac = { 0 };
    HACCEL hac = ::CreateAcceleratorTable(&ac, 1);
    lpFrameInfo->cb = sizeof(OLEINPLACEFRAMEINFO);
    lpFrameInfo->fMDIApp = FALSE;
    lpFrameInfo->hwndFrame = m_hOwner;
    lpFrameInfo->haccel = hac;
    lpFrameInfo->cAccelEntries = 1;
    return S_OK;
}

STDMETHODIMP CIEBrowserUI::Scroll(SIZE scrollExtant)
{ 
    return E_NOTIMPL;
}

STDMETHODIMP CIEBrowserUI::OnUIDeactivate(BOOL fUndoable)
{  
    return S_OK;
}

STDMETHODIMP CIEBrowserUI::OnInPlaceDeactivate(void)
{ 
    return OnInPlaceDeactivateEx(TRUE);
}

STDMETHODIMP CIEBrowserUI::DiscardUndoState(void)
{ 
    return E_NOTIMPL;
}

STDMETHODIMP CIEBrowserUI::DeactivateAndUndo(void)
{ 
    return E_NOTIMPL;
}

STDMETHODIMP CIEBrowserUI::OnPosRectChange(LPCRECT lprcPosRect)
{ 
    return E_NOTIMPL;
}

STDMETHODIMP CIEBrowserUI::GetWindow(HWND* phwnd)
{ 
    if (m_hOwner == NULL ) 
		return E_UNEXPECTED; 
    *phwnd = m_hOwner;
    return S_OK;
}

STDMETHODIMP CIEBrowserUI::ContextSensitiveHelp(BOOL fEnterMode)
{
    return S_OK;
}

STDMETHODIMP CIEBrowserUI::OnControlInfoChanged(void)      
{
    return S_OK;
}

STDMETHODIMP CIEBrowserUI::LockInPlaceActive(BOOL fLock)       
{ 
    return S_OK;
}

STDMETHODIMP CIEBrowserUI::GetExtendedControl(IDispatch** ppDisp)        
{
    if (ppDisp == NULL) 
		return E_POINTER;   
    if (m_hOwner == NULL) 
		return E_UNEXPECTED;
    if (m_pUnk == NULL) 
		return E_UNEXPECTED;
    return m_pUnk->QueryInterface(IID_IDispatch, (LPVOID*) ppDisp);
}

 
STDMETHODIMP CIEBrowserUI::OnFocus(BOOL fGotFocus)
{ 
    return S_OK;
}

STDMETHODIMP CIEBrowserUI::ShowPropertyFrame(void)
{ 
    return E_NOTIMPL;
}

STDMETHODIMP CIEBrowserUI::EnumObjects(DWORD grfFlags, IEnumUnknown** ppenum)
{
    return E_NOTIMPL;
}

STDMETHODIMP CIEBrowserUI::LockContainer(BOOL fLock)
{ 
    return S_OK;
}

STDMETHODIMP CIEBrowserUI::ParseDisplayName(IBindCtx *pbc, LPOLESTR pszDisplayName, ULONG* pchEaten, IMoniker** ppmkOut)
{
    return E_NOTIMPL;
}
 

